package cn.blog.dao.front;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import cn.blog.dao.conn.DataManager;
import cn.blog.dao.conn.ParamSet;
import cn.blog.dao.conn.RowDatas;
import cn.blog.entity.addBean.RzglArtInfo;

public class RzglArtInfoDao extends DataManager {
	private RowDatas<RzglArtInfo> artilce;

	public RzglArtInfoDao() {
		artilce = new ArtData();
	}

	/**
	 * 根据用户编号查询和文章状态查询文章
	 * 
	 * @param artId
	 *            用户编号
	 * @param state
	 *            文章状态
	 * @return
	 */
	public List<RzglArtInfo> getArticleAll(int userId, String state) {
		String sql = "SELECT a.art_id, a.art_title,ac.class_name,a.art_time,a.art_state FROM  	tb_article a "
				+ "LEFT JOIN tb_article_class ac on  a.art_class_id=ac.class_id where a.art_user_id = ? and a.art_state =?";
		return queryList(sql, new ParamSet(userId, state), artilce);

	}

	/**
	 * 根据用户编号查询和文章状态,文章编号，文章类型查询文章
	 * 
	 * @param userId
	 *            用户编号
	 * @param state
	 *            文章状态
	 * @param artId
	 *            文章编号
	 * @param cla
	 *            文章类型
	 * @return
	 */
	public List<RzglArtInfo> getArticle(int userId, String state, int artId, String cla) {
		String sql = "SELECT a.art_id, a.art_title,ac.class_name,a.art_time,a.art_state FROM  	tb_article a "
				+ "LEFT JOIN tb_article_class ac on  a.art_class_id=ac.class_id where a.art_user_id = ? and a.art_state =?"
				+ "and	(  a.art_id = ? or ac.class_name like '%" + cla + "%')";
		;

		return queryList(sql, new ParamSet(userId, state, artId), artilce);

	}

	public class ArtData implements RowDatas<RzglArtInfo> {
		@Override
		public RzglArtInfo getRowData(ResultSet rs) throws SQLException {
			RzglArtInfo artilce = new RzglArtInfo();
			artilce.setArtId(rs.getInt(1));
			artilce.setTitle(rs.getString(2));
			artilce.setArtClass(rs.getString(3));
			artilce.setArtTime(rs.getDate(4));
			artilce.setState(rs.getString(5));
			return artilce;

		}
	}
}
